Note
Click here to download the full example code
RecoBundles80 using AFQ API¶
An example using the AFQ API to run recobundles with the 80 bundle atlas.
import os.path as op
import plotly
from AFQ import api
import AFQ.data as afd
Get some example data¶
Retrieves Stanford HARDI dataset.
afd.organize_stanford_data(clear_previous_afq=True)
Out:
0%| | 0/5578 [00:00<?, ? MB/s]
0%| | 9/5578 [00:00<01:11, 78.33 MB/s]
1%| | 32/5578 [00:00<00:36, 151.86 MB/s]
1%|1 | 70/5578 [00:00<00:23, 233.74 MB/s]
2%|1 | 109/5578 [00:00<00:19, 274.99 MB/s]
3%|2 | 149/5578 [00:00<00:18, 300.80 MB/s]
3%|3 | 189/5578 [00:00<00:17, 315.97 MB/s]
4%|4 | 226/5578 [00:00<00:16, 329.89 MB/s]
5%|4 | 260/5578 [00:00<00:16, 326.75 MB/s]
5%|5 | 297/5578 [00:00<00:15, 337.63 MB/s]
6%|5 | 332/5578 [00:01<00:15, 335.89 MB/s]
7%|6 | 368/5578 [00:01<00:15, 337.89 MB/s]
7%|7 | 403/5578 [00:01<00:15, 340.19 MB/s]
8%|7 | 439/5578 [00:01<00:14, 345.92 MB/s]
9%|8 | 475/5578 [00:01<00:14, 341.38 MB/s]
9%|9 | 510/5578 [00:01<00:14, 343.75 MB/s]
10%|9 | 546/5578 [00:01<00:14, 341.55 MB/s]
10%|# | 581/5578 [00:01<00:14, 342.70 MB/s]
11%|#1 | 617/5578 [00:01<00:14, 340.76 MB/s]
12%|#1 | 652/5578 [00:02<00:14, 341.07 MB/s]
12%|#2 | 689/5578 [00:02<00:14, 343.96 MB/s]
13%|#2 | 724/5578 [00:02<00:14, 341.60 MB/s]
14%|#3 | 760/5578 [00:02<00:14, 343.14 MB/s]
14%|#4 | 795/5578 [00:02<00:14, 339.84 MB/s]
15%|#4 | 832/5578 [00:02<00:13, 345.14 MB/s]
16%|#5 | 867/5578 [00:02<00:13, 341.12 MB/s]
16%|#6 | 903/5578 [00:02<00:13, 342.95 MB/s]
17%|#6 | 938/5578 [00:02<00:13, 340.28 MB/s]
17%|#7 | 975/5578 [00:02<00:13, 344.94 MB/s]
18%|#8 | 1010/5578 [00:03<00:13, 337.60 MB/s]
19%|#8 | 1048/5578 [00:03<00:13, 340.07 MB/s]
19%|#9 | 1083/5578 [00:03<00:13, 341.90 MB/s]
20%|## | 1120/5578 [00:03<00:12, 343.20 MB/s]
21%|## | 1155/5578 [00:03<00:12, 343.19 MB/s]
21%|##1 | 1191/5578 [00:03<00:12, 342.36 MB/s]
22%|##1 | 1226/5578 [00:03<00:12, 342.26 MB/s]
23%|##2 | 1263/5578 [00:03<00:12, 345.19 MB/s]
23%|##3 | 1298/5578 [00:03<00:12, 341.95 MB/s]
24%|##3 | 1334/5578 [00:04<00:12, 344.00 MB/s]
25%|##4 | 1369/5578 [00:04<00:12, 340.91 MB/s]
25%|##5 | 1406/5578 [00:04<00:12, 346.59 MB/s]
26%|##5 | 1441/5578 [00:04<00:12, 341.25 MB/s]
26%|##6 | 1477/5578 [00:04<00:11, 344.94 MB/s]
27%|##7 | 1512/5578 [00:04<00:11, 339.68 MB/s]
28%|##7 | 1548/5578 [00:04<00:11, 345.21 MB/s]
28%|##8 | 1583/5578 [00:04<00:11, 337.72 MB/s]
29%|##9 | 1621/5578 [00:04<00:11, 345.07 MB/s]
30%|##9 | 1656/5578 [00:04<00:11, 341.28 MB/s]
30%|### | 1692/5578 [00:05<00:11, 343.59 MB/s]
31%|### | 1727/5578 [00:05<00:11, 338.68 MB/s]
32%|###1 | 1764/5578 [00:05<00:11, 346.59 MB/s]
32%|###2 | 1799/5578 [00:05<00:11, 341.01 MB/s]
33%|###2 | 1835/5578 [00:05<00:10, 344.92 MB/s]
34%|###3 | 1870/5578 [00:05<00:10, 340.22 MB/s]
34%|###4 | 1906/5578 [00:05<00:10, 344.46 MB/s]
35%|###4 | 1941/5578 [00:05<00:10, 338.34 MB/s]
35%|###5 | 1978/5578 [00:05<00:10, 344.95 MB/s]
36%|###6 | 2013/5578 [00:06<00:10, 340.24 MB/s]
37%|###6 | 2050/5578 [00:06<00:10, 333.98 MB/s]
37%|###7 | 2089/5578 [00:06<00:10, 336.41 MB/s]
38%|###8 | 2129/5578 [00:06<00:10, 340.12 MB/s]
39%|###8 | 2169/5578 [00:06<00:09, 342.19 MB/s]
40%|###9 | 2209/5578 [00:06<00:09, 343.44 MB/s]
40%|#### | 2248/5578 [00:06<00:09, 342.09 MB/s]
41%|####1 | 2288/5578 [00:06<00:09, 342.36 MB/s]
42%|####1 | 2328/5578 [00:06<00:09, 343.36 MB/s]
42%|####2 | 2368/5578 [00:07<00:09, 344.49 MB/s]
43%|####3 | 2407/5578 [00:07<00:09, 341.92 MB/s]
44%|####3 | 2447/5578 [00:07<00:09, 343.15 MB/s]
45%|####4 | 2487/5578 [00:07<00:08, 344.65 MB/s]
45%|####5 | 2527/5578 [00:07<00:08, 344.81 MB/s]
46%|####6 | 2567/5578 [00:07<00:08, 346.36 MB/s]
47%|####6 | 2606/5578 [00:07<00:08, 343.70 MB/s]
47%|####7 | 2646/5578 [00:07<00:08, 343.82 MB/s]
48%|####8 | 2686/5578 [00:07<00:08, 344.28 MB/s]
49%|####8 | 2726/5578 [00:08<00:08, 346.11 MB/s]
50%|####9 | 2765/5578 [00:08<00:08, 344.69 MB/s]
50%|##### | 2805/5578 [00:08<00:08, 345.51 MB/s]
51%|#####1 | 2845/5578 [00:08<00:07, 346.21 MB/s]
52%|#####1 | 2884/5578 [00:08<00:07, 358.06 MB/s]
52%|#####2 | 2920/5578 [00:08<00:07, 345.83 MB/s]
53%|#####2 | 2956/5578 [00:08<00:07, 339.03 MB/s]
54%|#####3 | 2993/5578 [00:08<00:07, 345.80 MB/s]
54%|#####4 | 3028/5578 [00:08<00:07, 341.40 MB/s]
55%|#####4 | 3064/5578 [00:09<00:07, 344.70 MB/s]
56%|#####5 | 3099/5578 [00:09<00:07, 338.60 MB/s]
56%|#####6 | 3139/5578 [00:09<00:07, 340.71 MB/s]
57%|#####6 | 3178/5578 [00:09<00:07, 340.37 MB/s]
58%|#####7 | 3218/5578 [00:09<00:06, 341.00 MB/s]
58%|#####8 | 3258/5578 [00:09<00:06, 342.51 MB/s]
59%|#####9 | 3297/5578 [00:09<00:06, 340.04 MB/s]
60%|#####9 | 3337/5578 [00:09<00:06, 341.75 MB/s]
61%|###### | 3377/5578 [00:09<00:06, 341.89 MB/s]
61%|######1 | 3416/5578 [00:10<00:06, 340.95 MB/s]
62%|######1 | 3456/5578 [00:10<00:06, 342.06 MB/s]
63%|######2 | 3496/5578 [00:10<00:06, 342.90 MB/s]
63%|######3 | 3535/5578 [00:10<00:05, 341.10 MB/s]
64%|######4 | 3575/5578 [00:10<00:05, 341.85 MB/s]
65%|######4 | 3615/5578 [00:10<00:05, 342.70 MB/s]
66%|######5 | 3654/5578 [00:10<00:05, 340.86 MB/s]
66%|######6 | 3694/5578 [00:10<00:05, 340.98 MB/s]
67%|######6 | 3734/5578 [00:11<00:05, 342.21 MB/s]
68%|######7 | 3774/5578 [00:11<00:05, 343.09 MB/s]
68%|######8 | 3813/5578 [00:11<00:05, 341.72 MB/s]
69%|######9 | 3853/5578 [00:11<00:05, 342.00 MB/s]
70%|######9 | 3893/5578 [00:11<00:04, 342.60 MB/s]
71%|####### | 3933/5578 [00:11<00:04, 343.07 MB/s]
71%|#######1 | 3972/5578 [00:11<00:04, 341.48 MB/s]
72%|#######1 | 4012/5578 [00:11<00:04, 342.83 MB/s]
73%|#######2 | 4052/5578 [00:11<00:04, 344.62 MB/s]
73%|#######3 | 4092/5578 [00:12<00:04, 345.56 MB/s]
74%|#######4 | 4131/5578 [00:12<00:04, 343.58 MB/s]
75%|#######4 | 4171/5578 [00:12<00:04, 343.93 MB/s]
75%|#######5 | 4211/5578 [00:12<00:03, 343.78 MB/s]
76%|#######6 | 4251/5578 [00:12<00:03, 344.31 MB/s]
77%|#######6 | 4290/5578 [00:12<00:03, 341.89 MB/s]
78%|#######7 | 4330/5578 [00:12<00:03, 342.75 MB/s]
78%|#######8 | 4370/5578 [00:12<00:03, 343.46 MB/s]
79%|#######9 | 4409/5578 [00:13<00:03, 342.56 MB/s]
80%|#######9 | 4446/5578 [00:13<00:03, 348.95 MB/s]
80%|######## | 4481/5578 [00:13<00:03, 343.12 MB/s]
81%|######## | 4518/5578 [00:13<00:03, 348.93 MB/s]
82%|########1 | 4553/5578 [00:13<00:02, 341.95 MB/s]
82%|########2 | 4589/5578 [00:13<00:02, 346.10 MB/s]
83%|########2 | 4624/5578 [00:13<00:02, 341.11 MB/s]
84%|########3 | 4660/5578 [00:13<00:02, 344.78 MB/s]
84%|########4 | 4695/5578 [00:13<00:02, 340.77 MB/s]
85%|########4 | 4732/5578 [00:13<00:02, 346.05 MB/s]
85%|########5 | 4767/5578 [00:14<00:02, 342.75 MB/s]
86%|########6 | 4803/5578 [00:14<00:02, 344.64 MB/s]
87%|########6 | 4838/5578 [00:14<00:02, 341.79 MB/s]
87%|########7 | 4875/5578 [00:14<00:02, 346.83 MB/s]
88%|########8 | 4910/5578 [00:14<00:01, 341.99 MB/s]
89%|########8 | 4946/5578 [00:14<00:01, 345.10 MB/s]
89%|########9 | 4981/5578 [00:14<00:01, 339.64 MB/s]
90%|########9 | 5018/5578 [00:14<00:01, 348.28 MB/s]
91%|######### | 5053/5578 [00:14<00:01, 338.32 MB/s]
91%|#########1| 5091/5578 [00:14<00:01, 334.06 MB/s]
92%|#########1| 5131/5578 [00:15<00:01, 337.07 MB/s]
93%|#########2| 5171/5578 [00:15<00:01, 339.76 MB/s]
93%|#########3| 5211/5578 [00:15<00:01, 341.25 MB/s]
94%|#########4| 5250/5578 [00:15<00:00, 339.12 MB/s]
95%|#########4| 5290/5578 [00:15<00:00, 339.36 MB/s]
96%|#########5| 5330/5578 [00:15<00:00, 340.30 MB/s]
96%|#########6| 5370/5578 [00:15<00:00, 341.25 MB/s]
97%|#########6| 5410/5578 [00:15<00:00, 341.92 MB/s]
98%|#########7| 5449/5578 [00:16<00:00, 340.06 MB/s]
98%|#########8| 5489/5578 [00:16<00:00, 341.67 MB/s]
99%|#########9| 5529/5578 [00:16<00:00, 342.19 MB/s]
100%|#########9| 5569/5578 [00:16<00:00, 343.22 MB/s]
100%|##########| 5578/5578 [00:16<00:00, 339.85 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2213.35 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2106.63 MB/s]
0%| | 0/71 [00:00<?, ? MB/s]
11%|#1 | 8/71 [00:00<00:00, 72.37 MB/s]
34%|###3 | 24/71 [00:00<00:00, 114.12 MB/s]
72%|#######1 | 51/71 [00:00<00:00, 172.11 MB/s]
100%|##########| 71/71 [00:00<00:00, 185.31 MB/s]
0%| | 0/4 [00:00<?, ? MB/s]
100%|##########| 4/4 [00:00<00:00, 86.43 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 2391.28 MB/s]
Set tractography parameters (optional)¶
We make this tracking_params which we will pass to the AFQ object which specifies that we want 50,000 seeds randomly distributed in the white matter.
We only do this to make this example faster and consume less space.
tracking_params = dict(n_seeds=50000,
random_seeds=True,
rng_seed=42)
Initialize an AFQ object:¶
We specify seg_algo as reco80 in segmentation_params. This tells the AFQ object to perform RecoBundles using the 80 bundles atlas in the segmentation step.
myafq = api.AFQ(bids_path=op.join(afd.afq_home,
'stanford_hardi'),
preproc_pipeline='vistasoft',
segmentation_params={"seg_algo": "reco80"},
tracking_params=tracking_params)
Out:
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz
0%| | 0.00/13.4k [00:00<?, ?B/s]
0%| | 33.0/13.4k [00:00<00:54, 243B/s]
1%|1 | 152/13.4k [00:00<00:21, 610B/s]
5%|5 | 696/13.4k [00:00<00:05, 2.14kB/s]
21%|##1 | 2.84k/13.4k [00:00<00:01, 7.42kB/s]
51%|#####1 | 6.82k/13.4k [00:00<00:00, 16.8kB/s]
68%|######8 | 9.12k/13.4k [00:00<00:00, 18.3kB/s]
94%|#########4| 12.6k/13.4k [00:00<00:00, 23.0kB/s]
13.4kB [00:00, 14.8kB/s]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_mask.nii.gz
0%| | 0.00/155 [00:00<?, ?B/s]
22%|##1 | 34.0/155 [00:00<00:00, 273B/s]
88%|########7 | 136/155 [00:00<00:00, 588B/s]
156B [00:00, 613B/s]
Visualizing bundles and tract profiles:¶
This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.
bundle_html = myafq.all_bundles_figure
plotly.io.show(bundle_html["01"])